package com.yequan.designpattern.proxy.dynamic_proxy.jdk.hello;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author yequan
 * @date 2021/12/02 16:59
 **/
public class Client {

    public static void main(String[] args) {
        System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");
        Hello hello = new Hello();
        InvocationHandler helloProxy = new HelloProxy(hello);
        HelloInterface hellointerface = (HelloInterface) Proxy.newProxyInstance(helloProxy.getClass().getClassLoader(), new Class[]{HelloInterface.class}, helloProxy);
        hellointerface.sayHello();

//        Hi hi = new Hi();
//        InvocationHandler hiProxy = new HelloProxy(hi);
//        HelloInterface hiInterface = (HelloInterface) Proxy.newProxyInstance(hiProxy.getClass().getClassLoader(), new Class[]{HelloInterface.class}, hiProxy);
//        hiInterface.sayHello();
    }

}
